package main

import (
	"fmt"
	"strings"
	"unicode"
)

func main() {
	var password string
	var improvement []string
	fmt.Print("请输入密码：")
	fmt.Scan(&password)

	score := 2
	if length_verify(password) {
		score += 1
	} else {
		improvement = append(improvement, "密码长度不足8位")
	}

	if string_include(password) {
		score += 1
	} else {
		improvement = append(improvement, "密码没有由3种以上字符组成")
	}

	if string_repetition(password) {
		score += 1
	} else {
		improvement = append(improvement, "密码中字符重复过多")
	}

	if score == 5 {
		fmt.Printf("%s的密码评分为%d\n", password, score)
	} else {
		fmt.Printf("%s的密码评分为%d\n", password, score)
		fmt.Printf("密码的不足之处是%v", improvement)
	}

}

// 验证密码长度是否为8位以上
func length_verify(password string) bool {
	return len(password) > 8
}

// 验证密码是否包含大写字母、小写字母、数字和其他字符中的三种及以上
func string_include(password string) bool {
	isupper, islower, isdigit, other_str := 0, 0, 0, 0
	for _, value := range password {
		if unicode.IsUpper(value) {
			isupper = 1
		}
	}
	for _, value := range password {
		if unicode.IsLower(value) {
			islower = 1
		}
	}
	for _, value := range password {
		if unicode.IsDigit(value) {
			isdigit = 1
		}
	}
	return (isupper + islower + isdigit + other_str) >= 3
}

// 验证密码中是否有字符重复三次以上
func string_repetition(password string) bool {
	for _, c := range password {
		if strings.Count(password, string(c)) >= 3 {
			return false
		}
	}
	return true
}
